﻿namespace D.Domain.SeedWork.EventBusUtil
{
    /// <summary>
    /// 实现的领域事件,分发Event
    /// </summary>
    public abstract class EventBus : IEventBus
    {
        /// 分布式缓存
        //private readonly IDistributedCache  

        [NotMapped]
        private List<INotification> domainEvents = new();

        public void AddEvent(INotification eventItem)
        {
            domainEvents.Add(eventItem);
        }

        public void AddEventIfAbsent(INotification eventItem)
        {
            if (!domainEvents.Contains(eventItem))
            {
                domainEvents.Add(eventItem);
            }
        }
        public void ClearEvents()
        {
            domainEvents.Clear();
        }

        public IEnumerable<INotification> GetEvents()
        {
            return domainEvents;
        }
    }
}
